package userFileModuleApi

import (
	"KumquatDrivesServices/StorageEngine"
	"KumquatDrivesServices/common/res"
	"KumquatDrivesServices/utils"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

type CancelUploadRequest struct {
	FileId string `json:"fileId" binding:"required"`
}

func (UserFileModuleApi) CancelUpload(c *gin.Context) {
	var req CancelUploadRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		res.FailWithCode(res.PARAM_ERR, c)
		return
	}
	userId := utils.GetUserId(c)
	uploadId := StorageEngine.EngineID(req.FileId)
	if err := uploadId.DeleteTempFileSize(userId); err != nil {
		res.FailWithCode(res.PARAM_ERR, c)
		return
	}
	if err := StorageEngine.Engine.DelTempFile(uploadId); err != nil {
		logrus.Errorf("DelTempFile failed:%v", err)
		res.FailWithCode(res.PARAM_ERR, c)
		return
	}
	res.OkWithData(map[string]any{}, c)

}
